import React from 'react';
import { Image } from '@tarojs/components';
import { useDarkMode } from './UseDarkMode';

function getStyle({ style, drakTintColor }: { drakTintColor: string, style: React.CSSProperties }) {
  const rStyle = { ...style };
  if (useDarkMode()) {
    if (drakTintColor) {
      rStyle.tintColor = drakTintColor;
    }
  }
  return rStyle;
}

// eslint-disable-next-line max-len
function DrakImage({ drakTintColor, style, ...otherProps }: { drakTintColor: string, style: React.CSSProperties }) {
  const realStyle = getStyle({ drakTintColor, style });
  return (
    <Image style={realStyle} {...otherProps} />
  );
}

export default DrakImage;
